home *** CD-ROM | disk | FTP | other *** search
-
- /*Size of the array*/
- #define kArraySizeH 10
- #define kArraySizeV 8
-
- /* Pictures*/
- PicHandle hexTile;
-
- /* Define constants that match our hexes */
- #define kHorizontalSpacing 32
- #define kVerticalSpacing 26
-
- /* Draw a tile */
-
- static void DrawHexTile(short h, short v)
- {
- Rect tileRectangle;
-
- /* Use the picture frame */
- tileRectangle = (**hexTile).picFrame;
- /* Move it to 0,0 */
- OffsetRect(&tileRectangle, -tileRectangle.left, -tileRectangle.top);
- /* Offset to the proper position */
- /* For every other line, offset a bit extra */
- if ((v & 1) == 0)
- OffsetRect(&tileRectangle, kHorizontalSpacing*h, kVerticalSpacing*v);
- else
- OffsetRect(&tileRectangle, kHorizontalSpacing*h + kHorizontalSpacing / 2, kVerticalSpacing*v);
- /* Draw it */
- DrawPicture(hexTile, &tileRectangle);
- } /*DrawHexTile*/
-
-
- /* Standard inits */
-
- static void InitToolbox(void) {
- InitGraf (&qd.thePort);
- InitFonts ();
- FlushEvents (everyEvent,0);
- InitWindows ();
- InitMenus ();
- TEInit ();
- InitDialogs (nil);
- InitCursor ();
- }
-
- /****************** Main program ******************/
-
- void main(void) {
- WindowPtr myWindow;
- Rect windowRectangle;
- short h,v;
-
- InitToolbox();
-
- /*Set up the window*/
- SetRect(&windowRectangle, 50, 50,
- 50 + kArraySizeH * kHorizontalSpacing + kHorizontalSpacing / 2,
- 50 + kArraySizeV * kVerticalSpacing + kVerticalSpacing / 3);
- myWindow = NewCWindow(nil, &windowRectangle, "\pHex grid demo", true, 0, (WindowPtr)-1L, false, 0);
- SetPort(myWindow);
-
- /*Load the picture*/
- hexTile = GetPicture(128); /*PICT resource #128.*/
-
- /*Draw all tiles!*/
- for ( h = 0 ; h < kArraySizeH ; h++)
- for ( v = 0 ; v < kArraySizeV ; v++)
- DrawHexTile(h, v);
-
- while ( ! Button () )
- ;
- } /*TextGrid*/
-